package com.craftyworks.alejandro.api;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.annotation.Resource;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"config/C2DMPushTest.xml"})
public class C2DMPushTestWithSpring {

    private String hansRID;
    
    private String ddamRID;
    
    @Resource
    private C2DMPush c2dm;
    
    @Resource(name="alejandroProperties")
    private Properties prop;
    
    @Before
    public void init() {
        hansRID = prop.getProperty("hans.rid");
        ddamRID = prop.getProperty("ddam.rid");
    }
    
    public void testSendMessage() throws IOException {
        Map<String, String> data = new HashMap<String, String>();
        data.put("androidExecuteType", "TRADING");
        data.put("sendMessage", "안녕");
        
        c2dm.sendMessage(hansRID, data);
    }
    
    @Test
    public void testTextSendMessage() throws IOException {
        
        Map<String, String> data = new HashMap<String, String>();
        data.put("androidExecuteType", "TEXT");
        data.put("sendMessage", URLEncoder.encode("안녕", "UTF-8"));
        
        c2dm.sendMessage(ddamRID, data);
    }    

}
